package org.jeecg.tool.bean;

import org.jeecg.tool.MyLicenseCreator;
import de.schlichtherle.license.*;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.prefs.Preferences;

@Data
@Accessors(chain = true)
public class LicenseCreatorParam {

    private String subject;

    private String priAlias = "privateKey";

    /**
     * 私钥文件路径
     */
    private String priKeyPath = "private.key";

    /**
     * 私钥密码
     */
    private String priPass;

    /**
     * 公钥密码
     */
    private String pubPass;

    private String licensePath = "license.lic";

    /**
     * 证书生效时间
     */
    private Date issuedTime = new Date();

    /**
     * 证书失效时间，1年后
     */
    private Date expiryTime;

    /**
     * 额外的服务器硬件校验信息
     */
    private String deviceInfo;

    public LicenseParam toLicenseParam(Class<?> c) {
        Preferences preferences = Preferences.userNodeForPackage(c);
        //设置对证书内容加密的秘钥
        CipherParam cipherParam = new DefaultCipherParam(getPubPass());
        KeyStoreParam privateStoreParam = new MyKeyStoreParam(MyLicenseCreator.class, getPriKeyPath(), getPriAlias(),
                getPubPass(), getPriPass());
        return new DefaultLicenseParam(getSubject(), preferences, privateStoreParam, cipherParam);
    }

}
